package com.wgchao.amc.mapstruct.mapper.expand;

import com.wgchao.amc.entity.autho.SysAuthoGroup;
import com.wgchao.amc.entity.autho.SysAuthoGroupFunc;
import com.wgchao.amc.mapstruct.DTOMapper;
import com.wgchao.amc.mapstruct.dto.SysAuthoGroupDTO;
import com.wgchao.amc.mapstruct.mapper.SysAuthoGroupFuncMapper;
import com.wgchao.amc.mapstruct.mapper.SysAuthoGroupMapper;
import com.wgchao.amc.repository.autho.SysAuthoGroupFuncRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName: SysAuthoGroupMapperExpand
 * @author: wgchao
 * @createTime: 2019/10/31 9:38 AM
 * @Description: TODO
 */
@Component
public class SysAuthoGroupMapperExpand implements DTOMapper<SysAuthoGroup, SysAuthoGroupDTO> {
    @Autowired
    private SysAuthoGroupMapper authoGroupMapper;
    @Autowired
    private SysAuthoGroupFuncRepository authoGroupFuncRepository;
    @Autowired
    private SysAuthoGroupFuncMapper authoGroupFuncMapper;

    @Override
    public SysAuthoGroup toEntity(SysAuthoGroupDTO sysAuthoGroupDTO) {
        return authoGroupMapper.toEntity(sysAuthoGroupDTO);
    }

    @Override
    public SysAuthoGroupDTO toDTO(SysAuthoGroup sysAuthoGroup) {
        return authoGroupMapper.toDTO(sysAuthoGroup);
    }

    @Override
    public List<SysAuthoGroup> toEntity(List<SysAuthoGroupDTO> sysAuthoGroupDTOS) {
        return authoGroupMapper.toEntity(sysAuthoGroupDTOS);
    }

    @Override
    public List<SysAuthoGroupDTO> toDTO(List<SysAuthoGroup> sysAuthoGroups) {
        return authoGroupMapper.toDTO(sysAuthoGroups);
    }

    public SysAuthoGroupDTO getFuncInfo(SysAuthoGroupDTO authoGroupDTO){
        List<SysAuthoGroupFunc> authoGroupFuncs = authoGroupFuncRepository.findAllByAgId(authoGroupDTO.getId());
        if(authoGroupFuncs!=null && !authoGroupFuncs.isEmpty()){
            authoGroupDTO.setGroupFuncs(authoGroupFuncMapper.toDTO(authoGroupFuncs));
        }
        return authoGroupDTO;
    }

}
